from common.base import Base, By, get_driver
from page.login_page import LoginPage
import time

class IndexPage(Base):
    index_url = "http://localhost:8080/ecshop/index.php"
    def font_text(self):
        """
        获取登录后的用户名
        :return:
        """
        return self.text((By.XPATH,'//*[@id="ECS_MEMBERZONE"]/font/font'))

    def user_logout(self):
        """
        点击退出按钮
        :return:
        """
        self.click((By.LINK_TEXT, '退出'))

    def login_click(self):
        """
        点击登录按钮
        :return:
        """
        self.click((By.XPATH,'//*[@id="ECS_MEMBERZONE"]/a[1]'))

    def scroll_to_element(self,locator):
        """
        滑动页面至目标商品
        :param locator:
        :return:
        """
        self.scroll_to_element(locator)

    def scroll_to_tail(self):
        self.scroll_to_browse_tail()

    def into_index_page(self):
        """
        进入首页方法
        :return:
        """
        self.login_user()
        time.sleep(1)
        self.click((By.XPATH,'//*[@id="mainNav"]/div/ul/li[1]/a'))

    def product_name(self,locator):
        """
        封装获取商品名字的方法
        :param locator:
        :return:
        """
        # self.text((By.XPATH,'//*[@id="ECS_FORMBUY"]/div'))
        self.text(locator)

    def page_quit(self):
        self.quit()

if __name__ == '__main__':
    driver = get_driver()
    indexpage = IndexPage(driver)
    indexpage.get(LoginPage.login_url)
    indexpage.into_index_page()